package com.ewzj.bigdata.mvp.ui.activity

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter

import com.ewzj.bigdata.R
import com.ewzj.bigdata.app.config.AppKey
import com.ewzj.bigdata.app.extensions.initcolor
import com.ewzj.bigdata.di.component.DaggerInformercialActivityComponent
import com.ewzj.bigdata.di.module.InformercialActivityModule
import com.ewzj.bigdata.mvp.contract.InformercialActivityContract
import com.ewzj.bigdata.mvp.presenter.HourseListPresenter
import com.ewzj.bigdata.mvp.presenter.InformercialActivityPresenter
import com.ewzj.bigdata.mvp.ui.adapter.InfoAdapter
import com.ewzj.bigdata.mvp.ui.adapter.OriginAdapter
import com.ewzj.bigdata.mvp.ui.adapter.SecondOriginAdapter
import com.jakewharton.rxbinding2.view.RxView
import com.jess.arms.base.BaseActivity
import com.jess.arms.di.component.AppComponent
import kotlinx.android.synthetic.main.activity_informercial.*
import kotlinx.android.synthetic.main.titile_red.*

class InformercialActivity : BaseActivity<InformercialActivityPresenter>(),InformercialActivityContract.View {
    val tiitle by lazy{intent.getStringExtra(AppKey.EXTRA_String)}
    override fun showLoading() {
        swipeRefreshLayout.isRefreshing=true
    }

    override fun launchActivity(intent: Intent?) {

    }

    override fun hideLoading() {
        swipeRefreshLayout.isRefreshing=false
    }

    override fun killMyself() {

    }

    override fun showMessage(message: String?) {

    }

    override fun setupActivityComponent(appComponent: AppComponent?) {
        DaggerInformercialActivityComponent.builder().appComponent(appComponent)
                .informercialActivityModule(InformercialActivityModule(this))
                .build().inject(this)
    }

    override fun initData(savedInstanceState: Bundle?) {
        RxView.clicks(iv_back).subscribe({finish()})
        if (tiitle.isNullOrEmpty()){
            ll_title.visibility= View.GONE
        }else{
            tv_title.text=tiitle
        }
        swipeRefreshLayout.initcolor()
        swipeRefreshLayout.setOnRefreshListener { mPresenter.getFirstData() }
        mPresenter.initRecyadapter()
        mPresenter.getFirstData()
    }

    override fun initView(savedInstanceState: Bundle?): Int {
        return R.layout.activity_informercial
    }

    override fun initadapter(adapter: SecondOriginAdapter) {

        rvcontent.layoutManager=LinearLayoutManager(this)
        adapter.setOnLoadMoreListener(object : BaseQuickAdapter.RequestLoadMoreListener {
            override fun onLoadMoreRequested() {
                mPresenter.loadmoreData()
            }

        },rvcontent)
        rvcontent.adapter=adapter
    }


}
